package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: DishController
 * USER: zhang
 * DATE: 2023/5/16
 * DESCRIPTION :B端-菜品信息表现层接口
 */
@Slf4j
@RestController
@RequestMapping("admin/dish")
@Api(tags = "B端-菜品信息表现层接口")
public class DishController {
    @Resource
    private DishService dishService;


    /**
     * 条件分页查询
     * @param dishPageQueryDTO 分页参数Bean
     * @return 全局通用返回信息(保存分页查询结果)
     */
    @ApiOperation("B端-条件分页查询菜品信息")
    @GetMapping("page")
    public Result<PageResult> selectByPage(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult=dishService.selectByPage(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增菜品信息(包含菜品口味)
     * @param dishDTO 用于接受菜品数据和菜品口味的Bean
     * @return 全局统一返回Bean
     */
    @ApiOperation("B端-新增菜品信息")
    @PostMapping
    public Result insertDish(@RequestBody DishDTO dishDTO){
        dishService.insertDish(dishDTO);
        return Result.success();
    }

    /**
     * 删除菜品信息
     * @param ids 要删除菜品信息的集合
     * @return
     */
    @ApiOperation("B端-删除菜品信息")
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Long> ids){
        dishService.deleteDish(ids);
        return Result.success();
    }

    /**
     * 基于id查询菜品
     * @param dishId 要查询菜品的id
     * @return
     */
    @ApiOperation("B端-基于Id查询菜品信息")
    @GetMapping("{dishId}")
    public Result<DishVO> selectDishVOById(@PathVariable Long dishId){
        DishVO dishVO = dishService.selectDishVOById(dishId);
        return Result.success(dishVO);
    }

    /**
     * 更新菜品信息
     * @param dishDTO 更新后的菜品完整信息Bean(▲包含菜品Id)
     * @return
     */
    @ApiOperation("B端-更新菜品信息")
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);
        return Result.success();
    }

    /**
     * 菜品的启售/停售
     * @param status 修改后的状态
     * @param id 要修改菜品的id
     * @return 全局通用返回Bean
     */
    @ApiOperation("B端-菜品信息的启售/停售")
    @PostMapping("status/{status}")
    public Result modifyStatus(@PathVariable Integer status,Long id){
        Dish dish = new Dish();
        dish.setId(id);
        dish.setStatus(status);
        dishService.modifyStatus(dish);
        return Result.success();
    }

    /**
     * 基于分类Id查询菜品信息集合
     *
     * @param categoryId 菜品分类Id
     * @return 分类Id对应的菜品数量
     */
    @ApiOperation("B端-基于分类Id查询菜品信息集合")
    @GetMapping("/list")
    public Result getDishByCategoryId(Long categoryId){
        List<Dish> dishList = dishService.getDishByCategoryId(categoryId);
        return Result.success(dishList);
    }
}
